package leecode

func longestCommonSubsequenceLCR(text1 string, text2 string) int {
	dp := make([][]int, len(text1)+1) // dp数组是 text1 从 0,i-1 text2从0,j-1的公共子序列的长度
	for i := 0; i < len(dp); i++ {
		dp[i] = make([]int, len(text2)+1)
	}
	var result int
	for i := 1; i < len(dp); i++ {
		for j := 1; j < len(dp[i]); j++ {
			if text1[i-1] == text2[j-1] {
				dp[i][j] = dp[i-1][j-1] + 1
			} else {
				dp[i][j] = max(dp[i-1][j], dp[i][j-1])
			}
			result = max(result, dp[i][j])
		}
	}
	return result
}
